<?php include "antet.php"; include "func.php";
/*Id Name Owner Cord. (x)
 1 Apala A 9 - 35
 2 BBBBBBBBBBBBBB B 43 - 7
 3 CCCCCCCCCC C 30 - 30
 4 town_of_A A 8 - 35
 */
//echo 888 % 100;
getmapdata();
/*
 INSERT INTO `devana`.`map` (
 `x` ,
 `y` ,
 `type` ,
 `subtype` ,
 `imgno` ,
 `name` ,
 `owner` ,
 `townsid` ,
 `level`
 )
 VALUES (
 '44', '100', '1', '5', '0', 'Unknown', '1', '0', '0-0-0-0-0-0-0-0'
 );
 */
function text($a)
{
	echo "</br>".ucfirst ($a);
}
function a($a)
{
	echo "
Line no ".$a;
}
function b($a)
{
	echo "</br>".print_r($a,true);
}
function mapsubtype($x,$y,$a)
{
	a($x+1,$y);
	a($x-1,$y);
	a($x,$y+1);
	a($x,$y-1);
	a($imgno = rand(0, 9));
	$name = mapname($terratype);
}
function getmapdata()
{
	global $db_id;
	$startxat = 0;
	$startyat = 0;
	$source = file('default/newmap1', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
	$lines = $source;
	$total = count($lines);
	//$total = 1;
	for ($c = 0;$c < $total; $c++)
	{
		//a($lines[c]);
		$lines[$c] = explode(" ", $lines[$c]);
		$lines[$c][0] += $startxat;
		$lines[$c][1] += $startyat;

		if ($lines[$c][2] != 0 && $lines[$c][2] != 1 && $lines[$c][2] != 2)
		{
			$lines[$c][2] = "1";
		}
		$subtype = rand(0,9);
		$i = $lines[$c][2];
		$m = findtypey($lines[$c][0],$lines[$c][1]+1,$source);
		$g = findtypex($lines[$c][0]+1,$lines[$c][1],$source);
		$n = findtypey($lines[$c][0],$lines[$c][1]-1,$source);
		$o = findtypex($lines[$c][0]-1,$lines[$c][1],$source);
		$imgno = $i.$m.$g.$n.$o;
		$name = mapname($i,$m,$g,$n,$o);
		//$imgno = $lines[$c+1][2].$lines[$c][2].$lines[$c-1][2].$lines[$c][2];
		/*$sql = "
		INSERT INTO `devana`.`map` (`x`, `y`, `type`, `subtype`, `imgno`, `name`, `owner`, `townsid`, `level`) VALUES ('".$lines[$c][0]."', '".$lines[$c][1]."', '".$lines[$c][2]."', '".$subtype."', '".$imgno."', '".$name."', '1', '0', '0-0-0-0-0-0-0-0');";
*/
$sql = "
INSERT INTO `devana`.`map` VALUES ('".$lines[$c][0]."', '".$lines[$c][1]."', '".$lines[$c][2]."', '".$subtype."', '".$imgno."', '".$name."', '1', '0', '0-0-0-0-0-0-0-0');";

	$result=mysql_query($sql, $db_id);
/*
	$fp = fopen('mapdata.sql', 'a+');
fwrite($fp, $sql);
fclose($fp);*/
		//a($sql);
a($c);
	}


}
function findtypex($x,$y,$lines)
{
	//b(array_keys($lines,$x));
	//b($lines[array_search($y, )]);
	$total = count($lines);
	for ($c = 0;$c < $total; $c++)
	{
		$lines[$c] = explode(" ", $lines[$c]);
		if ($lines[$c][0] == $x)
		{
			//a($lines[$c]);
			if ($lines[$c][1] == $y)
			{
				//b($lines[$c]);
				return $lines[$c][2];
			}
		}
	}/**/
	return "X";
}
function findtypey($x,$y,$lines)
{
	//b(array_keys($lines,$x));
	//b($lines[array_search($y, )]);
	$total = count($lines);
	for ($c = 0;$c < $total; $c++)
	{
		$lines[$c] = explode(" ", $lines[$c]);
		if ($lines[$c][1] == $y)
		{
			//a($lines[$c]);
			if ($lines[$c][0] == $x)
			{
				//b($lines[$c]);
				return $lines[$c][2];
			}
		}
	}/**/
	return "Y";
}
function style1($kon,$vow)
{//"m o r d o th"
	$text = "";
	$text = $kon[rand(1, count($kon))];
		$text .= $vow[rand(0, count($vow)-1)];
		$text .= $kon[rand(0, count($kon)-1)];
		$text .= $kon[rand(0, count($kon)-1)];
		$text .= $vow[rand(0, count($vow)-1)];
		return $text;
}
function style2($kon,$vow)
{//"o r d o th"
	$text = "";
	$text = $vow[rand(0, count($vow)-1)];
		$text .= $kon[rand(0, count($kon)-1)];
		$text .= $kon[rand(0, count($kon)-1)];
		$text .= $vow[rand(0, count($vow)-1)];
		$text .= $kon[rand(0, count($kon)-1)];
		return $text;//$kon[rand(1, count($kon))];
}
function style0($kon,$vow)
{//"o r o th"
	$text = "";
	$text = $vow[rand(0, count($vow)-1)];
		$text .= $kon[rand(0, count($kon)-1)];
		$text .= $vow[rand(0, count($vow)-1)];
		$text .= $kon[rand(0, count($kon)-1)];
		return $text;
}
function style3($kon,$vow)
{//"b o r - k i n th"
	$text = "";
	$text = $kon[rand(0, count($kon)-1)];
		$text .= $vow[rand(0, count($vow)-1)];
		$text .= $kon[rand(0, count($kon)-1)];
		$text .= " - ";
		$text2 = $kon[rand(0, count($kon)-1)];
		$text2 .= $vow[rand(0, count($vow)-1)];
		return $text.ucfirst ($text2 );
}
function mapname($terratype,$m,$g,$n,$o)
{
	$kon = array("b","c","d","f","g","h","j","k","l","m","n",
	"p","q","r","s","t","v","w","x","y","z");
	$vow = array("a","e","i","o","u");
	$text = "";

	$uth = array("ea","ord","nd","ein","ath","rth");
	//$uth = array("sea","fiord","land","forest ath","mountain rth");
	for ($i = 0; $i < 10;$i++){
		$nam = rand(0, 3);
		if ($nam == 0) $text = ucfirst ( style0($kon,$vow) );
		if ($nam == 1) $text = ucfirst ( style1($kon,$vow) );
		if ($nam == 2) $text = ucfirst ( style2($kon,$vow) );
		if ($nam == 3) $text = ucfirst ( style3($kon,$vow) );

		if ($terratype == 0)
		{
			$text .= "ia Sea";
			//$uth[rand(0, count($uth)-1)];
		}//text($text);
		if ($terratype == 1)
		{
			if ($m == 0 || $g == 0 || $n == 0 || $o == 0)
			{
				$text .= "ord Shore";
			}
			else if ($m == 2 || $g == 2 || $n == 2 || $o == 2)
			{
				$text .= "ath Forest";
			}
			else
			{
				$text .= "nd Plain";
			}
		}
		if ($terratype == 2)
		{
			$text .= "th Mountain";
		}
		return $text;
	}
}
/*
 ^>V<

 */
?>